# -*- coding: utf-8 -*-
"""
@Time    : 2024/7/5 18:24 
@Author  : ZhangShenao 
@File    : inherit.py 
@Desc    : 类的继承
"""
from abc import ABC, abstractmethod


class Entity(ABC):
    """抽象父类"""

    def __init__(self, title: str, entity_type: str):
        """
        构造函数
        :param title: 标题
        :param entity_type: 实体类型
        """

        self.title = title
        self.entity_type = entity_type

    def get_title(self) -> str:
        """
         获取标题
        :return: 标题
        """
        return self.title

    @abstractmethod
    def get_content_length(self) -> int:
        """
        获取内容长度,要求子类实现
        :return: 内容长度
        """
        raise Exception('function get_content_length is not implemented')


class Book(Entity):
    BOOK_ENTITY_TYPE = 'book'  # Book的entity_type

    """书籍类"""

    def __init__(self, title: str, author: str, content: str):
        """
        构造函数
        :param title: 标题
        :param author: 作者
        :param content: 内容
        """

        # 调用父类的构造函数
        super().__init__(title, Book.BOOK_ENTITY_TYPE)

        # 初始化子类的属性
        self.author = author
        self.__content = content

    def get_content_length(self) -> int:
        return len(self.__content)


class Video(Entity):
    """视频类"""
    VIDEO_ENTITY_TYPE = 'video'  # Video的entity_type

    def __init__(self, title: str, author: str, duration: int):
        """
        构造函数
        :param title: 标题
        :param author: 作者
        :param duration: 时长
        """

        # 调用父类的构造函数
        super().__init__(title, Video.VIDEO_ENTITY_TYPE)

        # 初始化子类的属性
        self.author = author
        self.duration = duration

    def get_content_length(self) -> int:
        return self.duration


if __name__ == '__main__':
    # 创建一个Book对象
    book = Book('Python编程', '张三', 'Python是一种高级编程语言')
    print(f'book的标题: {book.get_title()}, book的内容长度: {book.get_content_length()}')

    # 创建一个Video对象
    video = Video('Python编程视频', '张三', 120)
    print(f'video的标题: {video.get_title()}, video的内容长度: {video.get_content_length()}')

    # 创建一个Entity对象,会报错,因为Entity是抽象类,不能实例化
    # TypeError: Can't instantiate abstract class Entity without an implementation for abstract method 'get_content_length'
    # entity = Entity('test', 'test')
